package info.magnolia.blossom.sample.cv.components;

import info.magnolia.blossom.sample.cv.ListOfCVs;
import info.magnolia.module.blossom.annotation.TabFactory;
import info.magnolia.module.blossom.annotation.Template;
import info.magnolia.module.blossom.annotation.TemplateDescription;
import info.magnolia.module.blossom.dialog.TabBuilder;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.jcr.Node;
import javax.servlet.http.HttpServletRequest;

/**
 * Created with IntelliJ IDEA.
 * User: peterbalazs
 * Date: 3/1/13
 * Time: 1:51 PM
 * To change this template use File | Settings | File Templates.
 */
@Template(title = "Confirmation", id = "blossomSample:components/confirmation")
@TemplateDescription("Confirmation Component containing confirmation message and two buttons (yes/no)")
@Controller
public class ConfirmationComponent {

    @RequestMapping("/cvtemplate/confirmation")
    public String render(final Node page, final ModelMap model, final HttpServletRequest request) {
        model.put(ListOfCVs.PARAM_CV_ID, request.getParameter(ListOfCVs.PARAM_CV_ID));
        return "components/confirmation.jsp";
    }

    @TabFactory("Settings")
    public void settingsTab(final TabBuilder tab) {
        tab.addEdit("confirmationMessage", "Confirmation Message", "This message will be shown on the confirmation component");
        tab.addEdit("yesButtonMsg", "First Button Text", "This label will appear on the first button");
        tab.addUuidLink("yesButtonLink", "First Button Target Page", "This is the page which will be loaded when pressing the first button. The CV ID is passed.");
        tab.addEdit("noButtonMsg", "Second Button Text", "This label will appear on the second button");
        tab.addUuidLink("noButtonLink", "Second Button Target Page", "This is the page which will be loaded when pressing the second button. The CV ID is passed.");
    }
}
